import { MenuItemDefinition } from '@amcax/base';
import { PRODUCT_EVENT } from '@app-cad/common/Constants';
import { userEvents } from '@app-cad/module';
import { RefDocTypes } from '@app-cad/pages/product-support/consts';
import { ProductTreeNode } from '../../types';

export const rename: MenuItemDefinition<ProductTreeNode> = {
  id: 'rename',
  children: '重命名',
  hidden: ({ props: { parent, type } }) =>
    !parent || // root node has no parent
    !RefDocTypes.includes(type),
  onClick: ({ props: node }) =>
    userEvents.emit(PRODUCT_EVENT.PENDING_RENAME_DOC, node),
};
